package hust.rpc.lb;

import hust.rpc.pojo.Channel;
import hust.rpc.pojo.RpcRequest;

import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

public class RoundRobinLoadBalance implements LoadBalance {

    private static final AtomicLong counter = new AtomicLong(0);

    @Override
    public Channel next(List<Channel> channels, RpcRequest request) {
        int index = (int) (counter.getAndIncrement() % channels.size());
        return channels.get(index);
    }
}
